package com.tools.common.container;

import com.tools.common.object.Note;

import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;

/**
 * 自定义 List 集合容器的
 * 默认实现，继承自 AbsOwnList 类
 * 拥有 OwnRow 的默认实现功能
 * 以及 AbsOwnList 类的扩展功能
 * 基本兼容原生 List 的方法
 * */
@Note("自定义 List 集合容器的默认实现，继承自 AbsOwnList 类" +
        "拥有 OwnRow 的默认实现功能，以及 AbsOwnList 类的" +
        "扩展功能，基本兼容原生 List 的方法")
public class OwnList<T> extends AbsOwnList<T> implements Serializable {

    @Note("序列号 UID")
    private static final long serialVersionUID = -1500300698771191333L;

    public OwnList() {
    }

    public OwnList(int initSize) {
        super(initSize);
    }

    @SafeVarargs
    public OwnList(T... array) {
        super(array);
    }

    @SafeVarargs
    public OwnList(Comparator<? super T> c, T... array) {
        super(c, array);
    }

    public OwnList(Iterable<? extends T> iterable) {
        super(iterable);
    }

    public OwnList(Iterable<? extends T> iterable, Comparator<? super T> c) {
        super(iterable, c);
    }

    public OwnList(ListEnum implEnum, int initSize) {
        super(implEnum, initSize);
    }

    @SafeVarargs
    public OwnList(ListEnum implEnum, T... array) {
        super(implEnum, array);
    }

    @SafeVarargs
    public OwnList(ListEnum implEnum, Comparator<? super T> c, T... array) {
        super(implEnum, c, array);
    }

    public OwnList(ListEnum implEnum, Iterable<? extends T> iterable) {
        super(implEnum, iterable);
    }

    public OwnList(ListEnum implEnum, Iterable<? extends T> iterable, Comparator<? super T> c) {
        super(implEnum, iterable, c);
    }

    /* *******************************************************************************************
     *
     *          链式增删改方法
     *
     * *******************************************************************************************
     * */

    @Override
    public OwnList<T> add(T obj) {
        super.add(obj);
        return this;
    }

    @Override
    public OwnList<T> add(int index, T obj) {
        super.add(index, obj);
        return this;
    }

    @SafeVarargs
    @Override
    public final OwnList<T> addAll(T... objs) {
        super.addAll(objs);
        return this;
    }

    @SafeVarargs
    @Override
    public final OwnList<T> addAll(int index, T... array) {
        super.addAll(index, array);
        return this;
    }

    @Override
    public OwnList<T> addAll(Iterable<? extends T> objs) {
        super.addAll(objs);
        return this;
    }

    @Override
    public OwnList<T> addAll(int index, Collection<? extends T> objs) {
        super.addAll(index, objs);
        return this;
    }

    @Override
    public OwnList<T> addAll(int index, OwnRows<? extends T> objs) {
        super.addAll(index, objs);
        return this;
    }

    @Override
    public OwnList<T> addFirst(T obj) {
        super.addFirst(obj);
        return this;
    }

    @Override
    public OwnList<T> remove(int index) {
        super.remove(index);
        return this;
    }

    @Override
    public OwnList<T> remove(Object obj) {
        super.remove(obj);
        return this;
    }

    @Override
    public final OwnList<T> removeAll(Object... objs) {
        super.removeAll(objs);
        return this;
    }

    @Override
    public OwnList<T> removeAll(Iterable<?> objs) {
        super.removeAll(objs);
        return this;
    }

    @Override
    public OwnList<T> set(int index, T newValue) {
        super.set(index, newValue);
        return this;
    }

    @Override
    public OwnList<T> setFirst(T newValue) {
        super.setFirst(newValue);
        return this;
    }

    @Override
    public OwnList<T> setLast(T newValue) {
        super.setLast(newValue);
        return this;
    }

    public OwnList<T> subRow(int fromIndex, int toIndex) {
        protected_checkRangeIndex(fromIndex, toIndex);
        OwnList<T> result = new OwnList<>(toIndex - fromIndex);
        for (int i = fromIndex ; i < toIndex ; i++) {
            result.add(super.get(i));
        }
        return result;
    }
}
